/**
 * 基础model,系统权限相关功能
 * 在src/store/index.js 中被挂载到store上，命名为 sys
 * **/
import { APIPath } from "@/util/api/index";
import axios from "@/util/axios"; // 自己写的工具函数，封装了请求数据的通用接口
import { message } from "antd";
import { Dispatch } from "@/store";

const defaultState: any = {};

export default {
  state: defaultState,
  reducers: {},

  effects: (dispatch: Dispatch) => ({
    async getEnergyList() {
      try {
        const res: any = await axios.get(APIPath.getEnergy);
        return res;
      } catch (err) {
        message.error("网络错误，请重试");
      }
      return;
    },

    async updateEnergy(params: {
      id: number;
      min_energy: number;
      max_energy: number;
    }) {
      try {
        const res: any = await axios.post(APIPath.postUpdateEnergy, params);
        return res;
      } catch (err) {
        message.error("网络错误，请重试");
      }
      return;
    },

    async getUserLevelRuleList() {
      try {
        const res: any = await axios.get(APIPath.getUserLevel);
        return res;
      } catch (err) {
        message.error("网络错误，请重试");
      }
      return;
    },

    async updateUserLevel(params: any) {
      try {
        const res: any = await axios.post(APIPath.postUpdateUserLevel, params);
        return res;
      } catch (err) {
        message.error("网络错误，请重试");
      }
      return;
    },

    async getPoolRule() {
      try {
        const res: any = await axios.get(APIPath.getPoolRule);
        return res;
      } catch (err) {
        message.error("网络错误，请重试");
      }
      return;
    },

    async updatePondRule(params: any) {
      try {
        const res: any = await axios.post(APIPath.postUpdatePool, params);
        return res;
      } catch (err) {
        message.error("网络错误，请重试");
      }
      return;
    },
  }),
};
